//
//  LRLabelView.m
//  Common
//
//  Created by shiqing guo on 2018/11/8.
//  Copyright © 2018年 www.bitkinetic.com. All rights reserved.
//

#import "LRLabelView.h"
#import "Macro.h"
#import "GlobalUtil.h"
#import "UIView+DDAddition.h"

@interface LRLabelView ()
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UILabel *lblContent;
@end


@implementation LRLabelView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        [self addSubview:self.lblTitle];
        [self addSubview:self.lblContent];
    }
    return self;
}

- (void)setTitle:(nonnull NSString *)title
       titleFont:(nonnull UIFont *)titleFont
     titleHeight:(CGFloat)titleHeight
      titleColor:(nonnull UIColor *)titleColor
         content:(nonnull NSString *)content
     contentFont:(nonnull UIFont *)contentFont
   contentHeight:(CGFloat)contentHeight
    contentColor:(nonnull UIColor *)contentColor
{
    self.lblTitle.text = title;
    self.lblTitle.font = titleFont;
    self.lblTitle.textColor = titleColor;
    self.lblTitle.height = titleHeight;
    self.lblTitle.width = [GlobalUtil sizeFortext:title withFont:titleFont constrainedToSize:CGSizeMake(CGFLOAT_MAX, titleHeight)].width;
    
    self.lblContent.text = content;
    self.lblContent.font = contentFont;
    self.lblContent.textColor = contentColor;
    self.lblContent.width = self.width - self.lblTitle.right;
    CGFloat tempHeight = [GlobalUtil sizeFortext:content withFont:contentFont constrainedToSize:CGSizeMake(self.lblContent.width, CGFLOAT_MAX)].height;
    self.lblContent.height = (tempHeight >= contentHeight)?tempHeight:contentHeight;
    self.height = self.lblContent.height;
    
    self.lblContent.left = self.lblTitle.right;
}

+ (CGFloat)heightWithTitle:(nonnull NSString *)title
                    titleFont:(nonnull UIFont *)titleFont
                  titleHeight:(CGFloat)titleHeight
                      content:(nonnull NSString *)content
               contentFont:(nonnull UIFont *)contentFont
                frameWidth:(CGFloat)width
{
    CGFloat titleWidth = [GlobalUtil sizeFortext:title withFont:titleFont constrainedToSize:CGSizeMake(CGFLOAT_MAX, titleHeight)].width;
    CGFloat contentWidth = width - titleWidth;
    CGFloat tempHeight = [GlobalUtil sizeFortext:content withFont:contentFont constrainedToSize:CGSizeMake(contentWidth, CGFLOAT_MAX)].height;
    return tempHeight;
}

#pragma mark - 懒加载
- (UILabel *)lblTitle
{
    if (!_lblTitle) {
        _lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 20.0f)];
    }
    return _lblTitle;
}

- (UILabel *)lblContent
{
    if (!_lblContent) {
        _lblContent = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10.0f, 20.0f)];
        _lblContent.numberOfLines = 0;
    }
    return _lblContent;
}



@end
